package com.brsya.movie.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.brsya.movie.R;


/**
 * Created by Brsya
 * CreateDate: 2022/5/28  13:33
 * Description:
 * 分集View
 */
public class ItemPartView extends LinearLayout {
    private ConstraintLayout clPartBox;
    private TextView tvPartText;
    private View vPlayIcon;

    private int index;
    private LinearLayout llPartBox;
    private View vStartPadding;
    private View vEndPadding;

    public ItemPartView(Context context) {
        super(context);
        init();
    }

    public ItemPartView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ItemPartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View rootView = LayoutInflater.from(getContext()).inflate(R.layout.item_part, this, true);
        initView();
    }

    private void initView() {
        clPartBox = findViewById(R.id.cl_part_box);
        tvPartText = findViewById(R.id.tv_part_text);
        vPlayIcon = findViewById(R.id.v_play_icon);
        llPartBox = findViewById(R.id.ll_part_box);
        vStartPadding = findViewById(R.id.v_start_padding);
        vEndPadding = findViewById(R.id.v_end_padding);
    }

    /**
     * 设置选中状态
     *
     * @param status 是否选中
     */
    public void setPlayStatus(boolean status) {
        if (status) {
            clPartBox.setBackgroundResource(R.drawable.bg_part_select);
            tvPartText.setTextColor(0xFF2363CA);
            //            vPlayIcon.setVisibility(VISIBLE);
        } else {
            clPartBox.setBackgroundResource(R.drawable.bg_part_default);
            tvPartText.setTextColor(0x99333333);
            //            vPlayIcon.setVisibility(GONE);
        }
    }

    public void setText(String text) {
        tvPartText.setText(text);
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setLeftAndRightPadding(boolean left, boolean right) {
        vStartPadding.setVisibility(left ? View.VISIBLE : View.GONE);
        vEndPadding.setVisibility(right ? View.VISIBLE : View.GONE);
    }
}
